local ma__diqin = fk.CreateSkill{
  name = "ma__diqin",
}

Fk:loadTranslationTable{
  ["ma__diqin"] = "缔亲",
  [":ma__diqin"] = "当你每回合体力值首次变化后，你可以获得一名其他角色至多两张牌并交给其等量的牌，然后其选择一项：<br>"..
  "1.与你各摸一张牌；2.弃置你一张牌。",
  ["#ma__diqin"] = "缔亲：获得一名角色至多两张牌并还给其等量的牌，其选择与你摸牌或弃置你的牌",
  ["#ma__diqin-give"] = "缔亲：交给 %dest %arg张牌",
  ["#ma__diqin-choose"] = "缔亲：选择与%src各摸一张牌，或弃置其一张牌",
  ["ma__diqin-draw"] = "各摸一张牌",
  ["ma__diqin-discard"] = "弃置其一张牌",

  ["$ma__diqin1"] = "",
  ["$ma__diqin2"] = "",
}

ma__diqin:addEffect(fk.HpChanged, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(ma__diqin.name) and not player:isKongcheng() and
      player:usedSkillTimes(ma__diqin.name, Player.HistoryTurn) == 0 then
    local turn_event = player.room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
    if turn_event == nil then return false end
    local changehp_events = player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function (e)
      return e.data.who == player
    end, Player.HistoryTurn)
    if #changehp_events == 1 and changehp_events[1].data == data then
      return true
    end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    --[[player:drawCards(2, ma__diqin.name)]]
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player, false), function (p)
      return not p:isNude() 
    end)
    if #targets > 0 then
    local to = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = targets,
      skill_name = ma__diqin.name,
      prompt = "#ma__diqin",
      cancelable = true,
    })
    if #to > 0 then
      to = to[1]
      local getcards = room:askToChooseCards(player, {
      target = to,
      min = 1,
      max = 2,
      flag = "he",
      skill_name = ma__diqin.name,
    })
      room:moveCardTo(getcards, Card.PlayerHand, player, fk.ReasonPrey, ma__diqin.name, nil, false, player)
      local n = #getcards
      if player.dead or to.dead or player:isNude() then return end
      local cards = player:getCardIds("he")
      if #cards > n then
        cards = room:askToCards(player, {
          min_num = n,
          max_num = n,
          include_equip = true,
          skill_name = ma__diqin.name,
          prompt = "#ma__diqin-give::"..to.id..":"..n,
          cancelable = false,
        })
      end
      room:moveCardTo(cards, Card.PlayerHand, to, fk.ReasonGive, ma__diqin.name, nil, false, player)
      local choices = {"ma__diqin-draw", "ma__diqin-discard"}
      local choice = room:askToChoice(to, {
        choices = choices,
        skill_name = ma__diqin.name,
        prompt = "#ma__diqin-choose:::"..player.id,
        all_choices = {"ma__diqin-draw", "ma__diqin-discard"}
      })
      if choice == "ma__diqin-draw" then
        to:drawCards(1, ma__diqin.name)
          if not player.dead then
        player:drawCards(1, ma__diqin.name)
        end
      else 
        if not player:isNude() then
        local card = room:askToChooseCard(to, {
          target = player,
          skill_name = ma__diqin.name,
          flag = "he",
        })
        room:throwCard(card, ma__diqin.name, player, to)
      end  
      end
    end
    end
  end,
})

return ma__diqin